﻿using System.Diagnostics;
using System.Text;
using Ycg.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Ycg.Utility;

namespace Ycg.Test
{


    /// <summary>
    ///This is a test class for RSATest and is intended
    ///to contain all RSATest Unit Tests
    ///</summary>
    [TestClass()]
    public class RSATest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for CreateRSAKey
        ///</summary>
        [TestMethod()]
        public void CreateRSAKeyTest()
        {
            string publicKeyPath = @"c:\publickey.txt";
            string privateKeyPath = @"c:\privatekey.txt";
            RSA.CreateRSAKey(publicKeyPath, privateKeyPath);
            //Assert.Inconclusive("A method that does not return a value cannot be verified.");

            StringBuilder stringBuilder = new StringBuilder("{\"merid\":00000012,\"custno\":123}");

            for (int i = 0; i < 100; i++)
            {
                stringBuilder.Append("{\"merid\":00000012,\"custno\":123}");
            }

            //string encrypt =
               // "hD6m9KY0RKmt0Cb4TMXHqfO2W27jCFQrZwg7DTnOoZ5S4iJbK+xLf/YUIzNt51AWmR7iaFw6cPjQMYnv/Xf8z5YipLnFdpwWSqaVlISGFiU9G5+yjck0eXNxiZPb7K4rwpUYU/q3PSuyX/r+4vydQ/Y5kIzxJvnpsa6nSK4iY6BRNcmpEHqtTg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FsFQvqbRMxgqGZnOBhEmZTnZ7bmfWhGEcbKcwDtDteNqa4s4djqhpZ9WtRs86oL4RQ8/sbAqPce50piHeniA2CBRnkXrKqSpNRXTZJ5+I360w1bTkjX6alGIuuYd2jdSCucsr75nEWDv9DX4Fo20jWtooX1qf/69wyGaLiL8LbsBShBlRKYk8k8vlEceUhMJfcisVvLGh/z0swDwFiL3OksQzjAsJ2tkBOoO3yp6FhpsRMb+aK3z2wMeR95/Vg9CwVXsu6BN8oXbLUEGrKrTlb2HQLS17Qv2MZBY00bS14XcfVpsbr5ewSMGptB1BBp2JhZnvOcoGVY2MySEJ5yONpjoOJPAbODCWMHbTHNI0F1yPHDJ6HtEPGJ1WxnXqW5NXHe7eB8nXMCpe9+o3Enr6ksgtVG0oeg8qVRKjMHAJ8lU8c1hRE2xeQm/zyX9+qkUudtK8ahhA2bJB96IsknSxqYIwdp5R1dGwvz8EncktNG3/Lj/lRGE6uH1bK6KXu2GxF99vxtCaptFtGSOxe/cpHlouwk30JDwxPBI9PJFOk+wdzIM+pqMBxncA+jT21k7mV2tASgZ6YHXru474N8eMWAWdqxW2vg4G3BAoFHcKHBpm9JZpSCjqvjF9Zdq4/qhHtsKuydAYA28brbmDbtyPb3x87+EfUlIM60pxjFdc8+lp0wbqfxwGaNe33GUgl0zSFcSnlvsbSwYaXX25NLhxszogDf4U=";
            string encrypt = RSA.Encrypt(FileHelper.ReadContent(publicKeyPath), stringBuilder.ToString());
            Console.WriteLine(encrypt);
            //Trace.WriteLine(encrypt);

            Console.WriteLine(RSA.Decrypt(FileHelper.ReadContent(privateKeyPath), encrypt));
            //Trace.WriteLine(RSA.Decrypt(FileHelper.ReadContent(privateKeyPath), encrypt));
        }
    }
}